package com.zou.controller.proscenium;

import com.zou.controller.proscenium.common.InitCommon;
import com.zou.pojo.Info;
import com.zou.service.InfoService;
import com.zou.service.MaxMenuService;
import com.zou.service.MinMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class ShownewsController {
    @Autowired
    private InfoService infoService;
    @Autowired
    private MaxMenuService maxMenuService;
    @Autowired
    private MinMenuService minMenuService;

    @GetMapping("/proscenium/shownews/{id}")
    public String shownews(@PathVariable int id, Model model) {
        model = new InitCommon(infoService, maxMenuService, minMenuService, model).initHtml();

        if (!infoService.addInfoHitsById(id)) {
            return "forward:index";
        }
        try {
            Info info = infoService.querySomeInfoByInfo(new Info().setInfoId(id)).get(0);
            model.addAttribute("info", info);
        } catch (Exception e) {
            e.printStackTrace();
            return "forward:index";
        }

        return "proscenium/shownews";
    }
}
